// 自己实现一个curry方法

function add(a, b, c) {
  return a + b + c;
}

const curriedAdd = curry(add);

console.log(curriedAdd(1, 2, 3))
console.log(curriedAdd(1, 2)(3))
console.log(curriedAdd(1)(2, 3))
console.log(curriedAdd(1)(2)(3))

function curry(func) {
  return function curriedFn(...args) {
    if (args.length < func.length) {
      return function () {         // 第一次少写了这行
        return curriedFn(...args.concat(Array.from(arguments)));
      }
    }
    return func(...args);
  }
}

function aaa() {
  return function (...arg) {
    console.log(arg, 'arg');
    return function () {
      console.log(Array.from(arguments), 'arguments');
    }
  }
}

const bbb = aaa(1, 2, 3, 4, 5);
const ccc = bbb(6, 7, 8, 9, 10);
ccc(11, 12, 13);
